var api = require('../../utils/api.js');
var app = getApp();
Page({
    data: {
        imgs:'//img10.360buyimg.com/n1/jfs/t1/245642/19/19201/110355/66ebeeefF250aa107/abca6ddf87c27d07.jpg',
        types:[],
        type_name:'',
        type_id:'',
        key:'',
        page:0,
        lists:[]
    },
    currentPageNumber: 1,
    onLoad() {

        this.setData({
            _api: api,
            page:0
        });
        this.getalltypes();
        this.getallsuqiu();
    },
    onShow() {
      
    },

    /**
     * 上拉刷新
     */
    onReachBottom() {
        console.log('111');
        wx.showLoading({
          title: '加载中...',
          icon:'none'
        })
        setTimeout(() => {
            this.getallsuqiu();
            wx.hideLoading();
        }, 500);
    
    },
    
    bindPickerChange(ret){
        console.log(ret);
        var i=ret.detail.value;
        var types=this.data.types;
        var type_name=types[i].name;
        var type_id=types[i].id;
        this.setData({
            type_name:type_name,
            type_id:type_id,
            page:0,
            lists:[]
        })

        this.getallsuqiu();
    },

    getkeys(ret){
        console.log(ret);
        var key=ret.detail.value;
        this.setData({
            key:key,
            page:0,
            lists:[]
        })
        this.getallsuqiu();
    },

    getallsuqiu(){
        console.log('*******');
        var lists=this.data.lists;
        var page=this.data.page;
        var key=this.data.key;
        var type_id=this.data.type_id;

        var that=this;
        api.post({
            url: 'orderlist/getalllistbykey',
            data: {page:page,key:key,type_id:type_id},
            success: data => {
                var info=data.data;
                console.log(info) 
                
                info.forEach(function(item,index){
                    console.log(item);
                    lists.push(item);
                })

                that.setData({
                    lists:lists,
                    page:page+1
                })
            }
        })


    },
 
    previewImage(e) {
        wx.previewImage({
            current: '', // 当前显示图片的http链接
            urls: [e.currentTarget.dataset.previewUrl] // 需要预览的图片http链接列表
        });

    },

    onShareAppMessage() {
        return {
            title: '好玩的,都在这儿~~',
            path: '/pages/index/index'
        }
    },
        /**
     *  获取分类
     */
    getalltypes(){
        var that=this;
        api.post({
            url: 'orderlist/getalltypes',
            data: {},
            success: data => {
                var info=data.data;
                console.log(info) 
                that.setData({
                    types:info
                })

            }
        })
    },
    seeinfo(ret){
        console.log(ret);
        var id=ret.currentTarget.dataset.id;

        wx.navigateTo({
          url: '/pages/index/info?id='+id
        })

    }

});
